/***********************************************************************
 * Copyright © 2013 Beals Software
 * All Rights Reserved
************************************************************************
Author: Donald Beals
Date: August 28, 2013
Description: An object to simplify working with paths.
polygonpathfinding.codeplex.com
****************************** Change Log ******************************
08.28.13 - Created initial file. (dbeals)
***********************************************************************/

function Path()
{
	this.waypoints = new Array();
	
	this.getNextWaypoint = function()
	{
		if(this.waypoints.length == 0)
			return null;
		return this.waypoints[0];
	}
	
	this.getFinalWaypoint = function()
	{
		if(this.waypoints.length == 0)
			return null;
		return this.waypoints[this.waypoints.length - 1];
	}
	
	this.getDistanceToNextWaypoint = function(point)
	{
		var nextWaypoint = this.getNextwaypoint();
		if(nextWaypoint == null)
			return new Point(0, 0);
			
		return new Point(nextWaypoint.x - point.x, nextWaypoint.y - point.y);
	}
	
	this.addWaypoint = function(x, y)
	{
		this.waypoints.push(new Point(x, y));
	}
	
	this.addWaypoints = function(waypoints)
	{
		for(var index = 0; index < waypoints.length; ++index)
			this.addWaypoint(waypoints[index].x, waypoints[index].y);
	}
	
	this.popWaypoint = function()
	{
		if(this.waypoints == null || this.waypoints.length == 0)
			return new Point(0, 0);
			
		var output = this.getNextWaypoint();
		this.waypoints = this.waypoints.splice(0, 1);
		return output;
	}
	
	this.clear = function()
	{
		this.waypoints.length = 0;
	}
}